//
//	MsgBoxEx - how to customize a standard message box
//	Written by J Brown 2002
//	Freeware
//

#include <windows.h>
#include <tchar.h>

TCHAR szContents[] = _T("Windows will now wipe your harddisk!");
TCHAR szTitle[]    = _T("Hello");

HHOOK hMsgBoxHook;

LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	TCHAR ach[40];
	HWND hwnd;
	HWND hwndButton;

	if(nCode < 0)
		return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);

	switch(nCode)
	{
	case HCBT_ACTIVATE:

		// Get handle to the message box!
		hwnd = (HWND)wParam;

		SetWindowText(hwnd, _T("Message from Bill"));

		hwndButton = GetDlgItem(hwnd, IDOK);
		SetWindowText(hwndButton, _T("Thankyou"));
		
		return 0;

	}

	return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
}


int MsgBoxEx(HWND hwnd, TCHAR *szText, TCHAR *szCaption, UINT uType)
{
	int retval;

	// Install a window hook, so we can intercept the message-box
	// creation, and customize it
	hMsgBoxHook = SetWindowsHookEx(
		WH_CBT, 
		CBTProc, 
		NULL, 
		GetCurrentThreadId()			// Only install for THIS thread!!!
		);

	// Display a standard message box
	retval = MessageBox(hwnd, szText, szCaption, uType);

	// remove the window hook
	UnhookWindowsHookEx(hMsgBoxHook);

	return retval;
}


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nShowCmd)
{
	// Just display a standard message box.
	// It doesn't matter that we have no parent window or a
	// message-loop, because MessageBox has it's own message loop.

	MsgBoxEx(NULL, szContents, szTitle, MB_OK | MB_ICONSTOP);
		
	return 0;
}

